package com.allqj.sfx.application;

import com.allqj.sfx.application.dto.TableColumnDTO;
import com.allqj.sfx.domain.entity.TableHeader;
import com.allqj.sfx.domain.enums.PageEnum;
import com.allqj.sfx.domain.service.TableHeaderService;
import com.allqj.sfx.infrastructure.utils.JsonUtil;
import com.google.gson.reflect.TypeToken;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author sjw
 * @className TableHeaderApplicationService
 * @date 2022/7/21 10:44
 * @description: 列表表头
 */

@Component
public class TableHeaderApplicationService {
    // 领域层service
    private final TableHeaderService tableHeaderService;

    public TableHeaderApplicationService(TableHeaderService tableHeaderService) {
        this.tableHeaderService = tableHeaderService;
    }

    public List<TableColumnDTO> header(PageEnum table) {
        TableHeader tableHeader = tableHeaderService.header(table);
        if (tableHeader == null || tableHeader.getColumnJson() == null) return new ArrayList<>();
        return JsonUtil.jsonToObject(tableHeader.getColumnJson(),
                new TypeToken<List<TableColumnDTO>>() {}.getType());
    }
}
